package com.net.xpay.common.manager.impl;

import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import com.net.common.dao.BasicMapper;
import com.net.common.dao.Page;
import com.net.common.manager.AbstractManager;
import com.net.xpay.common.dao.SafePayBusinessAuthAuditRecordMapper;
import com.net.xpay.common.domain.SafePayBusinessAuthAuditRecord;
import com.net.xpay.common.manager.SafePayBusinessAuthAuditRecordManager;
import com.net.xpay.core.model.AdminSafePayBookAccountSearchModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;


@Component
public class SafePayBusinessAuthAuditRecordManagerImpl extends AbstractManager<SafePayBusinessAuthAuditRecord> implements SafePayBusinessAuthAuditRecordManager{

    @Autowired
    private SafePayBusinessAuthAuditRecordMapper mapper;


    @Override
    protected BasicMapper<Long, SafePayBusinessAuthAuditRecord> getMapper() {
        return mapper;
    }

    @Override
    public SafePayBusinessAuthAuditRecord findBySafePayBookAccountId(Long safePayBookAccountId) {
        Preconditions.checkArgument( safePayBookAccountId != null);
        SafePayBusinessAuthAuditRecord condition = new SafePayBusinessAuthAuditRecord();
        condition.setSafePayBookAccountId(safePayBookAccountId);
        return getByCondition(condition);
    }

    @Override
    public List<SafePayBusinessAuthAuditRecord> search(AdminSafePayBookAccountSearchModel searchModel) {
        Preconditions.checkArgument(searchModel != null);
        Page page = new Page(searchModel);
        page.addOrder("id", "desc");

        return nonEmptyList(mapper.search(searchModel, page));
    }



    @Override
    public long searchCount(AdminSafePayBookAccountSearchModel searchModel) {
        Preconditions.checkArgument(searchModel != null);
        return mapper.searchCount(searchModel);
    }

    @Override
    public List<SafePayBusinessAuthAuditRecord> list(AdminSafePayBookAccountSearchModel searchModel) {
        Preconditions.checkArgument(searchModel != null);
        return nonEmptyList(mapper.list(searchModel));
    }

    @Override
    public SafePayBusinessAuthAuditRecord findById(Long userId, Long id) {
        Preconditions.checkArgument(userId != null && id != null);
        SafePayBusinessAuthAuditRecord condition = new SafePayBusinessAuthAuditRecord();
        condition.setId(id);
        condition.setUserId(userId);
        return getByCondition(condition);
    }

    @Override
    public SafePayBusinessAuthAuditRecord findByBusinessName(Long userId, String businessName) {
        Preconditions.checkArgument(userId != null && !Strings.isNullOrEmpty(businessName));

        SafePayBusinessAuthAuditRecord condition = new SafePayBusinessAuthAuditRecord();
        condition.setUserId(userId);
        condition.setBusinessName(businessName);
        return getByCondition(condition);
    }


}
